package com.bell.atensettings.settingDetails;

import com.bell.atensettings.R;

import android.app.Activity;
import android.content.Context;
import android.hardware.display.DisplayManager;
import android.os.Bundle;
import android.view.DisplayManagerAw;
import android.view.KeyEvent;
import android.widget.TextView;

public class DisplayAreaSettings extends Activity
{
    private DisplayManagerAw displayManager;
    private TextView tv_title;
    private TextView tv_data;
    private int mPercent = 100;
    
    private void initView()
    {
        tv_title = (TextView) findViewById(R.id.setting_title);
        tv_data = (TextView) findViewById(R.id.tv_data);
        mPercent = displayManager.getDisplayAreaPercent(0);
        
        tv_title.setText(getIntent().getStringExtra("title"));
        tv_data.setText(mPercent + "%");
    }

    @Override
    public void onBackPressed()
    {
        super.onBackPressed();
        overridePendingTransition(R.anim.start, R.anim.push_left_out);
    }

    @Override
    protected void onCreate(Bundle bundle)
    {
        super.onCreate(bundle);
        setContentView(R.layout.area_settings);
        
        displayManager = (DisplayManagerAw) getSystemService(Context.DISPLAY_SERVICE_AW);
        initView();
    }

    @Override
    protected void onResume()
    {
        super.onResume();
    }

    @Override
    public boolean onKeyDown(int keycode, KeyEvent event)
    {
        switch (keycode)
        {
            case KeyEvent.KEYCODE_DPAD_LEFT:
            case KeyEvent.KEYCODE_DPAD_DOWN:
                if (mPercent > 90)
                    mPercent--;
                displayManager.setDisplayAreaPercent(0, mPercent);
                tv_data.setText(mPercent + "%");
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
            case KeyEvent.KEYCODE_DPAD_UP:
                if (mPercent < 100)
                    mPercent++;
                displayManager.setDisplayAreaPercent(0, mPercent);
                tv_data.setText(mPercent + "%");
                break;
            default:
                break;
        }
        return super.onKeyDown(keycode, event);
    }
    
}
